package ibms_rcp;

import ibms_rcp.db.DataBaseManager;

import java.net.URL;

import org.apache.log4j.PropertyConfigurator;
import org.eclipse.core.runtime.FileLocator;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class Activator implements BundleActivator {

	private static BundleContext context;

	static BundleContext getContext() {
		return context;
	}

	/*
	 * (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
	 */
	public void start(BundleContext bundleContext) throws Exception {
//		System.out.println("start");
		URL confURL = bundleContext.getBundle().getEntry("log4j.properties"); 
		PropertyConfigurator.configure(FileLocator.toFileURL(confURL).getFile());
		Activator.context = bundleContext;
		
		DataBaseManager.getConnection();
	}

	/*
	 * (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
	 */
	public void stop(BundleContext bundleContext) throws Exception {
		Activator.context = null;
		
		DataBaseManager.freeConnection();
	}

}
